﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using WORD = Microsoft.Office.Interop.Word;
using System.Windows.Forms;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace Excel2Word
{
    public class AppStore
    {
        public static Workbook targetWorkbook;

        public static WORD.Document targetDoc;

        public static FrmExcelOperation curOprateWindow;


        public static List<SourceElement> listEle = new List<SourceElement>();

        public static Form mainForm;


        public static List<SourceElement> GetTestData()
        {
            if (listEle.Count > 0) return listEle;

            SourceElement se1 = new SourceElement();
            se1.fieldName = "姓名";
            se1.fieldValue = "史蒂文";
            SourceElement se2 = new SourceElement();
            se2.fieldName = "年龄";
            se2.fieldValue = "40";
            return new List<SourceElement>() { se1, se2 };
        }


        public static void Serilize()
        {
            IFormatter serilizer = new BinaryFormatter();

            FileStream fileStream = new FileStream("ExcelDataSource.txt", FileMode.Create, FileAccess.ReadWrite);

            serilizer.Serialize(fileStream, listEle);

            fileStream.Close();
        }

        public static void deSerilize()
        {
            IFormatter serilizer = new BinaryFormatter();

            FileStream fileStream = new FileStream("ExcelDataSource.txt", FileMode.Open, FileAccess.ReadWrite);

            AppStore.listEle = (List<SourceElement>)serilizer.Deserialize(fileStream);

            fileStream.Close();
        }


    }

}
